package com.example.project1.controller;

import com.example.project1.information.User;
import com.example.project1.service.UserService;
import com.example.project1.service.UserServiceImp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Result")
@RestController
@RequestMapping("/test")
public class UserController {
   @Autowired
   private UserServiceImp userServiceImp;

   @GetMapping(value = "/insert")
   @Operation(summary = "用户注册")
   //@RequestMapping(value = "/insert",method = RequestMethod.POST)
   public String insertuser(@Parameter(name = "username",description = "用户名") String username,@Parameter(name = "password",description = "输入密码") String password,@Parameter(name ="repassword",description = "再次输入密码") String repassword) {
       boolean result=false;
       if(password.equals(repassword))
        result= userServiceImp.insertuser(username,password);
       else return "两次输入密码不一样";
       if(result) return "注册成功";
       else return "注册失败";
   }

   @GetMapping(value = "/login")
   @Operation(summary = "用户登录")
   public String login(@Parameter(name = "username", description = "用户名")  String username,@Parameter(name = "password", description = "密码") String password){
        User user = userServiceImp.getoneuser(username,password);
        if(user!=null)
        return "hello";
        else
            return "erro";
   }

   @GetMapping(value = "/delete")
   @Operation(summary = "用户注销")
   public String delete(@Parameter(name = "username",description = "用户名") String username){
       boolean flag=userServiceImp.deleteuser(username);
       if(flag)
       return "注销成功";
       else return "注销失败";
   }
//   @GetMapping("/hello")
//    @Operation(summary = "测试接口")
//    public String index(@Parameter(name = "name", description = "名称") String name) {
//        return "hello " + name;
//    }
//   @RequestMapping("/hello")
//    public String hello(){
//       return "hello";
//   }

}
